package com.road.vast.springboot;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;

import java.io.InputStream;
import java.util.zip.ZipInputStream;

/**
 * @Author 郭泽鹏
 * @Date 2020/6/23 0:04
 * @Version 1.0
 * 流程定义的部署
 * 流程数据添加到哪些表？
 * act_re_deployment：部署信息
 * act_re_procdef：流程定义的一些信息
 * act_ge_property：流程定义的bpmn文件及png文件
 */
public class ActivitiDeployment {
//    //使用 bpmn + png方式
//    public static void main(String[] args) {
//        //1、创建ProcessEngine对象
//        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//
//        //2、得到RepositoryService实例
//        RepositoryService repositoryService = processEngine.getRepositoryService();
//
//        //3、进行部署
//        Deployment deloyment = repositoryService.createDeployment()
//                .addClasspathResource("diagram/holiday.bpmn")   //添加bpmn资源
//                .addClasspathResource("diagram/holiday.png")    //添加png资源
//                .name("请假申请单流程")
//                .deploy();
//
//        //4、输出部署的一些信息
//        System.out.println(deloyment.getName());
//        System.out.println(deloyment.getId());
//    }

    //使用 zip压缩包方式
    public static void main(String[] args) {
        //zip包 path
        String zipPath = "diagram/examine.zip";

        //1、创建ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        //2、得到RepositoryService实例
        RepositoryService repositoryService = processEngine.getRepositoryService();

        //3、转换出 ZipInputStream 流对象
        InputStream resourceAsStream = ActivitiDeployment.class.getClassLoader().getResourceAsStream(zipPath);

        //4、将InputStream流转化为ZipInputStream流
        ZipInputStream zipInputStream = new ZipInputStream(resourceAsStream);

        //5、进行部署
        Deployment deloyment = repositoryService.createDeployment()
                .addZipInputStream(zipInputStream)
                .name("体检流程-包含网关测试")
                .deploy();

        //4、输出部署的一些信息
        System.out.println(deloyment.getName());
        System.out.println(deloyment.getId());
    }
}
